from apps.view_models.book import BookViewModel


class GiftWishViewModel:
    def __init__(self, trades, trade_count_list):
        self.books = []
        self.trades = trades
        self.trade_count_list = trade_count_list
        self.books = self.__parse()

    def __parse(self):
        temp_list = []
        for x in self.trades:
            temp_list.append(self.__match(x))
        return temp_list

    def __match(self, trade):
        info = dict(
            count=0,
            id=trade.id,
            book=BookViewModel(trade.book)
        )
        for x in self.trade_count_list:
            if trade.isbn == x['isbn']:
                info['count'] = x['count']
        return info

